<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Set the value of the given option</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.ldap-search.html">« ldap_search</a></li>
      <li style="float: right;"><a href="function.ldap-set-rebind-proc.html">ldap_set_rebind_proc »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.ldap.html">LDAP 函数</a></li>
    <li>Set the value of the given option</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.ldap-set-option" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ldap_set_option</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ldap_set_option</span> &mdash; <span class="dc-title">Set the value of the given option</span></p>

 </div>

  <div class="refsect1 description" id="refsect1-function.ldap-set-option-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ldap_set_option</strong></span>(<span class="methodparam"><span class="type">?</span><span class="type"><span class="type"><a href="class.ldap-connection.html" class="type LDAP\Connection">LDAP\Connection</a></span><span class="type"></span></span> <code class="parameter">$ldap</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$option</code></span>, <span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type">string</span>|<span class="type">int</span>|<span class="type">bool</span></span> <code class="parameter">$value</code></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Sets the value of the specified option to be <code class="parameter">value</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ldap-set-option-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">ldap</code></dt>

     <dd>

      <p class="para">
       Either an <span class="classname"><a href="class.ldap-connection.html" class="classname">LDAP\Connection</a></span> instance, returned by
       <span class="function"><a href="function.ldap-connect.html" class="function">ldap_connect()</a></span>, to set the option for that connection,
       or <strong><code>null</code></strong> to set the option globally.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">option</code></dt>

     <dd>

      <p class="para">
       The parameter <code class="parameter">option</code> can be one of:
       <table class="doctable informaltable">
        
         <thead>
          <tr>
           <th>Option</th>
           <th>Type</th>
           <th>Available since</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td><strong><code>LDAP_OPT_DEREF</code></strong></td>
           <td><span class="type">int</span></td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_SIZELIMIT</code></strong></td>
           <td><span class="type">int</span></td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_TIMELIMIT</code></strong></td>
           <td><span class="type">int</span></td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_NETWORK_TIMEOUT</code></strong></td>
           <td><span class="type">int</span></td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_PROTOCOL_VERSION</code></strong></td>
           <td><span class="type">int</span></td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_ERROR_NUMBER</code></strong></td>
           <td><span class="type">int</span></td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_REFERRALS</code></strong></td>
           <td><span class="type">bool</span></td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_RESTART</code></strong></td>
           <td><span class="type">bool</span></td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_HOST_NAME</code></strong></td>
           <td><span class="type">string</span></td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_ERROR_STRING</code></strong></td>
           <td><span class="type">string</span></td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_DIAGNOSTIC_MESSAGE</code></strong></td>
           <td><span class="type">string</span></td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_MATCHED_DN</code></strong></td>
           <td><span class="type">string</span></td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_SERVER_CONTROLS</code></strong></td>
           <td><span class="type">array</span></td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_CLIENT_CONTROLS</code></strong></td>
           <td><span class="type">array</span></td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_X_KEEPALIVE_IDLE</code></strong></td>
           <td><span class="type">int</span></td>
           <td>PHP 7.1.0</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_X_KEEPALIVE_PROBES</code></strong></td>
           <td><span class="type">int</span></td>
           <td>PHP 7.1.0</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_X_KEEPALIVE_INTERVAL</code></strong></td>
           <td><span class="type">int</span></td>
           <td>PHP 7.1.0</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_X_TLS_CACERTDIR</code></strong></td>
           <td><span class="type">string</span></td>
           <td>PHP 7.1.0</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_X_TLS_CACERTFILE</code></strong></td>
           <td><span class="type">string</span></td>
           <td>PHP 7.1.0</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_X_TLS_CERTFILE</code></strong></td>
           <td><span class="type">string</span></td>
           <td>PHP 7.1.0</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_X_TLS_CIPHER_SUITE</code></strong></td>
           <td><span class="type">string</span></td>
           <td>PHP 7.1.0</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_X_TLS_CRLCHECK</code></strong></td>
           <td><span class="type">int</span></td>
           <td>PHP 7.1.0</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_X_TLS_CRLFILE</code></strong></td>
           <td><span class="type">string</span></td>
           <td>PHP 7.1.0</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_X_TLS_DHFILE</code></strong></td>
           <td><span class="type">string</span></td>
           <td>PHP 7.1.0</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_X_TLS_KEYFILE</code></strong></td>
           <td><span class="type">string</span></td>
           <td>PHP 7.1.0</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_X_TLS_PROTOCOL_MIN</code></strong></td>
           <td><span class="type">int</span></td>
           <td>PHP 7.1.0</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_X_TLS_RANDOM_FILE</code></strong></td>
           <td><span class="type">string</span></td>
           <td>PHP 7.1.0</td>
          </tr>

          <tr>
           <td><strong><code>LDAP_OPT_X_TLS_REQUIRE_CERT</code></strong></td>
           <td><span class="type">int</span></td>
           <td>PHP 7.0.5</td>
          </tr>

         </tbody>
        
       </table>

      </p>
      <p class="para">
       <strong><code>LDAP_OPT_SERVER_CONTROLS</code></strong> and 
       <strong><code>LDAP_OPT_CLIENT_CONTROLS</code></strong> require a list of
       controls, this means that the value must be an array of controls. A
       control consists of an <em class="emphasis">oid</em> identifying the control,
       an optional <em class="emphasis">value</em>, and an optional flag for
       <em class="emphasis">criticality</em>. In PHP a control is given by an
       array containing an element with the key <em class="emphasis">oid</em>
       and string value, and two optional elements. The optional
       elements are key <em class="emphasis">value</em> with string value
       and key <em class="emphasis">iscritical</em> with boolean value.
       <em class="emphasis">iscritical</em> defaults to <em class="emphasis"><strong><code>false</code></strong></em>
       if not supplied. See <a href="http://www.openldap.org/devel/cvsweb.cgi/~checkout~/doc/drafts/draft-ietf-ldapext-ldap-c-api-xx.txt" class="link external">&raquo;&nbsp;draft-ietf-ldapext-ldap-c-api-xx.txt</a>
       for details. See also the second example below.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">value</code></dt>

     <dd>

      <p class="para">
       The new value for the specified <code class="parameter">option</code>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ldap-set-option-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.ldap-set-option-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.1.0</td>
 <td>
  现在 <code class="parameter">ldap</code> 参数接受 <span class="classname"><a href="class.ldap-connection.html" class="classname">LDAP\Connection</a></span>
  实例，之前接受 <a href="language.types.resource.html" class="link">资源(resource)</a>。
 </td>
</tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.ldap-set-option-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4355">
    <p><strong>示例 #1 Set protocol version</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;$ds&nbsp;is&nbsp;a&nbsp;valid&nbsp;LDAP\Connection&nbsp;instance&nbsp;for&nbsp;a&nbsp;directory&nbsp;server<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">ldap_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">LDAP_OPT_PROTOCOL_VERSION</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Using&nbsp;LDAPv3"</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Failed&nbsp;to&nbsp;set&nbsp;protocol&nbsp;version&nbsp;to&nbsp;3"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <div class="example" id="example-4356">
    <p><strong>示例 #2 Set server controls</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;$ds&nbsp;is&nbsp;a&nbsp;valid&nbsp;LDAP\Connection&nbsp;instance&nbsp;for&nbsp;a&nbsp;directory&nbsp;server<br />//&nbsp;control&nbsp;with&nbsp;no&nbsp;value<br /></span><span style="color: #0000BB">$ctrl1&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"oid"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"1.2.752.58.10.1"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"iscritical"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;iscritical&nbsp;defaults&nbsp;to&nbsp;FALSE<br /></span><span style="color: #0000BB">$ctrl2&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"oid"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"1.2.752.58.1.10"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"value"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"magic"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;try&nbsp;to&nbsp;set&nbsp;both&nbsp;controls<br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">ldap_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">LDAP_OPT_SERVER_CONTROLS</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">$ctrl1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$ctrl2</span><span style="color: #007700">)))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Failed&nbsp;to&nbsp;set&nbsp;server&nbsp;controls"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.ldap-set-option-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    This function is only available when using OpenLDAP 2.x.x OR Netscape
    Directory SDK x.x.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.ldap-set-option-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.ldap-get-option.html" class="function" rel="rdfs-seeAlso">ldap_get_option()</a> - Get the current value for given option</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>